package com.cn.evaluate.handler;

import java.util.List;

import org.apache.log4j.Logger;
import org.dom4j.DocumentException;
import org.dom4j.Element;

public class FieldsHandler extends DefaultHandler {

	/**
	 * 日志管理
	 */
	public static Logger logger = Logger.getLogger(FieldsHandler.class);

	/**
	 * 构造函数
	 * 
	 * @param xmlFilePath
	 */
	public FieldsHandler(String xmlFilePath) {
		super(xmlFilePath);
	}

	/**
	 * 使用示例：给定项目，即可获得该项目的所有输入项名称，输入校验（最大、最小值之间）、输入格式、提示
	 * 
	 * @param args
	 * @throws DocumentException
	 */
	public static void main(String[] args) throws DocumentException {
		FieldsHandler handler = new FieldsHandler(
				"src/com/cn/evaluate/resource/height_weight.xml");
		String xpath = "/subject/fields/output/field";
		Element root = handler.getRootElement();
		List<?> elements = handler.getElement(root, xpath);
		for (int i = 0; i < elements.size(); ++i) {
			Element element = (Element) elements.get(i);
			logger.debug("名称：" + element.attribute("name").getValue());
			logger.debug("描述：" + element.attribute("descript").getValue());
			logger.debug("单位：" + element.attribute("unit").getValue());
			logger.debug("格式：" + element.attribute("format").getValue());
			logger.debug("库表字段：" + element.attribute("tablefield").getValue());
			logger.debug("===============");
		}

	}

}
